package com.zhyz.bookstore.service.impl;
/**
 * 后台管理业务层
 */

import com.zhyz.bookstore.dao.ManagerDao;
import com.zhyz.bookstore.dao.impl.ManagerDaoImpl;
import com.zhyz.bookstore.entity.Admin;
import com.zhyz.bookstore.entity.Book;
import com.zhyz.bookstore.entity.Category;
import com.zhyz.bookstore.entity.User;
import com.zhyz.bookstore.service.ManagerService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

public class ManagerServiceImpl implements ManagerService {
    private ManagerDao managerDao = new ManagerDaoImpl();
    @Override
    public Admin login(String username, String password) {
        return managerDao.login(username, password);
    }

    /**
     * 添加书籍类型
     * @param category
     */
    public void addCategory(Category category){
        category.setCategoryId(UUID.randomUUID().toString());
        managerDao.addCategory(category);
    }

    /**
     * 获取所有图书分类
     * @return
     */
    public List<Category> getAllCatrgory(){
        return managerDao.getAllCategory();
    }

    /**
     * 根据书籍类型编号查询书籍分类
     * @param CategoryId
     * @return
     */
    public Category getCategory(String CategoryId){
        return managerDao.getCategory(CategoryId);
    }

    /**
     * 修改书籍类型
     * @param category
     */
    public void upCategory(Category category){
        managerDao.upCategory(category);
    }

    /**
     * 删除书籍类型
     * @param CategoryId
     */
    public void delCategroy(String CategoryId){
        managerDao.delCategroy(CategoryId);
}

    public List<Book> getCategoryBook(String cid){
            return managerDao.getCategoryBook(cid);
    }

    /**
     * 添加图书
     * @param book
     */
    public void addBooks(Book book){
        book.setBookId(UUID.randomUUID().toString());
        managerDao.addBooks(book);
    }

    /**
     * 根据书籍ID查询书籍
     * @param BookId
     * @return
     */
    public Book getBooks(String BookId){
        return managerDao.getBooks(BookId);
    }

    /**
     * 修改图书信息
     * @param
     */
    public void upBook(String book_id, String book_name, String book_author, String book_press, String book_desc,
                       double book_price, String book_kunumber){
        managerDao.upBook(book_id, book_name, book_author, book_press, book_desc, book_price, book_kunumber);
    }

    /**
     * 删除书籍
     * @param bookId
     */
    public void delBook(String bookId){
        managerDao.delBook(bookId);
    }


    @Override
    public void addAdmin(Admin admin) {
        managerDao.addAdmin(admin);
    }

    @Override
    public void managerPassword(String username, String password) {
        Admin admin = new Admin(username, password, null, null, null);
        managerDao.managerPassword(admin);
    }

    @Override
    public void managerInformation(String username, String name, String sex, String tel) {
        Admin admin = new Admin(username, null, name, sex, tel);
        managerDao.managerInformation(admin);
    }

    @Override
    public List<User> findUsers() {
        return managerDao.findUsers();
    }

    @Override
    public void delUser(String userId) {
        managerDao.delUser(userId);
    }

}
